********************************************************************************
/*							CODE INFORMATION

	Project: Central bank communication and house price expectations
	
	Date: 	May 2025
	
	Purpose: Load/clean raw datasets, label relevant variables and output analysis datasets

    Inputs: 
	 A. Interest rate information provision experiment: 1. raw_data_infor_provision.dta
	 
	 B. Non-verbal communication experiment:            2. raw_data_non_verbal.dta
	 
	 C. Hypothetical vignette experiment:               3. raw_data_vignette_main.dta
														4. raw_vignette_pooled (for pooled analysis)
														
     D. Robustness experiments wave:                    5. raw_data_robust_wave

    Outputs (in sequence): 1. analysis_data_infor_provision.dta
						   2. analysis_data_infor_provision_descriptive.dta
						   3. analysis_data_non_verbal.dta
						   4. data_figureA2.csv
						   5. analysis_data_vignette_main.dta
						   6. analysis_vignette_pooled.dta
						   7. data_figureA4.csv
						   8. analysis_data_robust_wave.dta
						   9. analysis_data_pooled.dta

*/
********************************************************************************

clear
set more off
//Include your directories to the replication folder below: e.g. /Users/litang/Library/CloudStorage/Dropbox/RCT_Housing_new/data/replication
global sDIR = "INCLUDE DIRECTORY OF THE REPLICATION FOLDER"


cd "$sDIR"

//*********************************************************************************
//***********************  Clean "raw_data_infor_provision"  **********************
//*********************************************************************************

//****** For main analysis  *******
clear
set more off
cd "$sDIR"
use "$sDIR/raw_data_infor_provision.dta", clear

gen age_cat2 = .
replace age_cat2 = 1 if age >= 18 & age <= 30 
replace age_cat2 = 2 if age > 30 & age <= 45 
replace age_cat2 = 3 if age > 45 & age <= 55 
replace age_cat2 = 4 if age > 55

lab define age_vals2 1 "18 to 30" 2 "31 to 45" 3 "46 to 55" 4 "55 over"
lab values age_cat2  age_vals2

gen age_cat3 = .
replace age_cat3 = 1 if age >= 18 & age <= 30
replace age_cat3 = 2 if age > 35 & age <= 55
replace age_cat3 = 3 if age > 55

lab define age_vals3 1 "18 to 35" 2 "36 to 50" 3 "50 over"
lab values age_cat3  age_vals3

gen Employed = 0
replace Employed = 1 if Employment == 2
gen Income_6000 = 0
replace Income_6000 = 1 if Income >= 7
gen Inf_high_know = 0
replace Inf_high_know = 1 if inlist(Inf_know, 4,5,6,7)
gen H_Certain = 0
replace H_Certain = 1 if House_certain == 2

gen earn_top = .
replace earn_top = 1 if  earn_q == 3
replace earn_top = 0 if  inlist(earn_q, 1,2)

gen education = .
replace education = 1 if  Education > 2
replace education = 0 if  inlist(Education, 1,2)

replace post_Inf_fut = . if abs(post_Inf_fut) >= 100
replace inf_fut = . if abs(inf_fut) >= 100

replace House_fut = . if abs(House_fut) >= 100
replace post_House_fut = . if abs(post_House_fut) >= 100
replace House_fut = . if post_House_fut - House_fut >= 100 & group == 1

replace post_House_fut = 100 if abs(post_House_fut) > 100
replace House_fut = 100 if abs(House_fut) > 100

gen House_conf = House_certain
recode House_conf (2=-2)(1=0)(0=1)

replace Mortgage_fut = . if Mortgage_fut >= 100
replace post_Mortgage = . if post_Mortgage >= 100
replace post_Mortgage = . if post_Mortgage - Mortgage_fut >= 10  & group == 1
replace post_Mortgage = . if post_Mortgage - Mortgage_fut >= 10  & group == 2

gen diff_House = post_House_fut - House_fut
gen diff_House_f = post_House_fut_f - House_fut

//winsorize the change in forecasts
egen diff_House_low = pctile(diff_House), p(5)
replace diff_House = diff_House_low if diff_House < diff_House_low & diff_House != .

egen diff_House_high = pctile(diff_House), p(95)
replace diff_House = diff_House_high if diff_House > diff_House_high & diff_House != .

gen shock_ffr = .
replace shock_ffr = 1.1 - FFR_fut if inlist(group,1,2,3,4)
gen rev_House = post_House_fut - House_fut
gen rev_ffr = post_FFR - FFR_fut
gen rev_ffr_first =  rev_ffr

save "$sDIR/analysis_data_infor_provision.dta", replace

//****** For descriptive statistics  *******

use "$sDIR/raw_data_infor_provision.dta", clear

gen Employed = 0
replace Employed = 1 if inlist(Employment, 1,2)
gen Unemployed = 0
replace Unemployed = 1 if inlist(Employment, 0)

gen above_bachelor = .
replace above_bachelor = 1 if inlist(Education, 6,7,8)
replace above_bachelor = 0 if inlist(Education, 1,2,3,4,5)

lab define above_bachelor_vals2 0 "No" 1 "Yes"
lab values above_bachelor above_bachelor_vals2

gen R1 = 0
replace R1 = 1 if region == 1
gen R2 = 0
replace R2 = 1 if region == 2
gen R3 = 0
replace R3 = 1 if region == 3
gen R4 = 0
replace R4 = 1 if region == 4

//getting rid of large outliers and winsorizing
replace Mortgage_fut = . if Mortgage_fut >= 100
replace House_fut = . if abs(House_fut) >= 100
replace House_fut = . if abs(post_House_fut - House_fut) >= 20 & group == 1

egen House_fut_low_1 = pctile(House_fut) if group == 1, p(2.5)
replace House_fut = House_fut_low_1 if House_fut < House_fut_low_1 & House_fut != . & group == 1

egen House_fut_high_1 = pctile(House_fut) if group == 1, p(97.5)
replace House_fut = House_fut_high_1 if House_fut > House_fut_high_1 & House_fut != . & group == 1

egen House_fut_low_2 = pctile(House_fut) if group == 2, p(2.5)
replace House_fut = House_fut_low_2 if House_fut < House_fut_low_2 & House_fut != . & group == 2

egen House_fut_high_2 = pctile(House_fut) if group == 2, p(97.5)
replace House_fut = House_fut_high_2 if House_fut > House_fut_high_2 & House_fut != . & group == 2

egen House_fut_low_3 = pctile(House_fut) if group == 3, p(2.5)
replace House_fut = House_fut_low_3 if House_fut < House_fut_low_3 & House_fut != . & group == 3

egen House_fut_high_3 = pctile(House_fut) if group == 3, p(97.5)
replace House_fut = House_fut_high_3 if House_fut > House_fut_high_3 & House_fut != . & group == 3

egen House_fut_low_4 = pctile(House_fut) if group == 4, p(2.5)
replace House_fut = House_fut_low_4 if House_fut < House_fut_low_4 & House_fut != . & group == 4

egen House_fut_high_4 = pctile(House_fut) if group == 4, p(97.5)
replace House_fut = House_fut_high_4 if House_fut > House_fut_high_4 & House_fut != . & group == 4

egen Inf_fut_low_1 = pctile(inf_fut) if group == 1, p(2.5)
replace inf_fut = Inf_fut_low_1 if inf_fut < Inf_fut_low_1 & inf_fut != . & group == 1

egen Inf_fut_high_1 = pctile(inf_fut) if group == 1, p(97.5)
replace inf_fut = Inf_fut_high_1 if inf_fut > Inf_fut_high_1 & inf_fut != . & group == 1

egen Inf_fut_low_2 = pctile(inf_fut) if group == 2, p(2.5)
replace inf_fut = Inf_fut_low_2 if inf_fut < Inf_fut_low_2 & inf_fut != . & group == 2

egen Inf_fut_high_2 = pctile(inf_fut) if group == 2, p(97.5)
replace inf_fut = Inf_fut_high_2 if inf_fut > Inf_fut_high_2 & inf_fut != . & group == 2

egen Inf_fut_low_3 = pctile(inf_fut) if group == 3, p(2.5)
replace inf_fut = Inf_fut_low_3 if inf_fut < Inf_fut_low_3 & inf_fut != . & group == 3

egen Inf_fut_high_3 = pctile(inf_fut) if group == 3, p(97.5)
replace inf_fut = Inf_fut_high_3 if inf_fut > Inf_fut_high_3 & inf_fut != . & group == 3

egen Inf_fut_low_4 = pctile(inf_fut) if group == 4, p(2.5)
replace inf_fut = Inf_fut_low_4 if inf_fut < Inf_fut_low_4 & inf_fut != . & group == 4

egen Inf_fut_high_4 = pctile(inf_fut) if group == 4, p(97.5)
replace inf_fut = Inf_fut_high_4 if inf_fut > Inf_fut_high_4 & inf_fut != . & group == 4

gen diff_House = post_House_fut - House_fut

//winsorize the change in forecasts
egen diff_House_low = pctile(diff_House), p(5)
replace diff_House = diff_House_low if diff_House < diff_House_low & diff_House != .

egen diff_House_high= pctile(diff_House), p(95)
replace diff_House = diff_House_high if diff_House > diff_House_high & diff_House != .

//Inflation
gen diff_Inf = post_Inf_fut - inf_fut
//winsorize the change in forecasts
egen diff_Inf_low = pctile(diff_Inf), p(5)
replace diff_Inf = diff_Inf_low if diff_Inf < diff_Inf_low & diff_Inf != .
egen diff_Inf_high= pctile(diff_Inf), p(95)
replace diff_Inf = diff_Inf_high if diff_House > diff_Inf_high & diff_Inf != .
gen diff_Mortgage = post_Mortgage - Mortgage_fut
egen diff_Mortgage_low = pctile(diff_Mortgage), p(5)
replace diff_Mortgage = diff_Mortgage_low if diff_Mortgage < diff_Mortgage_low & diff_Mortgage != .
egen diff_Mortgage_high= pctile(diff_Mortgage), p(95)
replace diff_Mortgage = diff_Mortgage_high if diff_House > diff_Mortgage_high & diff_Mortgage != .
reg diff_Mortgage i.group  [pw = wt], r

replace Mortgage_fut = . if abs(Mortgage_fut) >= 40
replace inf_fut = . if abs(inf_fut) >= 70

save "$sDIR/analysis_data_infor_provision_descriptive.dta", replace
//*********************************************************************************
//***************************  Clean "raw_data_non_verbal"  ******************
//*********************************************************************************

clear
set more off
cd "$sDIR"
use "$sDIR/raw_data_non_verbal.dta", clear

lab define certain_vals2 4 "very certain" 3 "somwhat certain" 2 "somwhat uncertain" 1 "Very uncertain" 
lab values pre_house_certain  certain_vals2
lab values post_house_certain  certain_vals2

gen prior_knowledge_channel = .
replace prior_knowledge_channel = 1 if pre_knowledge == 2
replace prior_knowledge_channel = 0 if pre_knowledge != 2
lab define prior_vals2  1 "have knowledge of interest-house price" 0 "do not have knowledge of interest-house price" 
lab values prior_knowledge_channel  prior_vals2

gen information_correct = .
replace information_correct = 1 if awhatwasthepolicyinterestratedec == 1
replace information_correct = 0 if awhatwasthepolicyinterestratedec != 1
lab define information_vals2  1 "correct information" 0 "incorrect information" 
lab values information_correct information_correct_vals2

lab define signal_vals2 2 "Very positive signals" 1 "Positive signals" 0 "Neutral signals" -1 "Negative signals" -2 "Very negative signals" 

lab values face_evaluation signal_vals2 
lab values voice_evaluation signal_vals2 
lab values script_evaluation signal_vals2 
lab values overall_evaluation signal_vals2 

gen face_evaluation2 = .
replace face_evaluation2 = 1 if inlist(face_evaluation,2,1)
replace face_evaluation2 = 0 if inlist(face_evaluation,0)
replace face_evaluation2 = -1 if inlist(face_evaluation,-1,-2)

gen voice_evaluation2 = .
replace voice_evaluation2 = 1 if inlist(voice_evaluation,2,1)
replace voice_evaluation2 = 0 if inlist(voice_evaluation,0)
replace voice_evaluation2 = -1 if inlist(voice_evaluation,-1,-2)

gen script_evaluation2 = .
replace script_evaluation2 = 1 if inlist(script_evaluation,2,1)
replace script_evaluation2 = 0 if inlist(script_evaluation,0)
replace script_evaluation2 = -1 if inlist(script_evaluation,-1,-2)

gen overall_evaluation2 = .
replace overall_evaluation2 = 1 if inlist(overall_evaluation,2,1)
replace overall_evaluation2 = 0 if inlist(overall_evaluation,0)
replace overall_evaluation2 = -1 if inlist(overall_evaluation,-1,-2)

lab define house_better_vals2 1 "worse off" 2 "no diff" 3 "better off"
lab values house_better house_better_vals2

lab define gender_vals2 1 "Female" 2 "male" 
lab values gender gender_vals2

lab define employ_vals2 1 "Employed" 2 "Self-employed" 3 "Unemployed (including retired and out of labor force)"
lab values employment employ_vals2

lab define marriage_vals2 1 "Married/In civil partnership" 2 "Single/Divorced/Separated/Widowed"
lab values marriage marriage_vals2

lab define education_vals2 1 "Below high school" 2 "High school diploma (or equivalent)" 3 "Some college but no degree (including academic, vocational or occupational programs)" 4 "Associate/Junior College degree (including academic, vocational, or occupational programs)" 5 "Bachelor's Degree (For example: BA, BS)" 6 "Master's Degree (For example: MA, MBA, MS, MSW)" 7 "Doctoral Degree (For example: PhD)" 8 "Professional Degree (For example: MD, JD, DDS)"
lab values education education_vals2

lab define child_vals2 2 "No" 1 "Yes"
lab values child child_vals2

lab define income_vals2 1 "Less than $1,000" 2 "$1,000 - $1,999" 3 "$2,000 - $2,999" 4 "$3,000 - $3,999" 5 "$4,000 - $4,999" 6 "$5,000 - $5,999" 7 "$6,000 - $7,499" 8 "$7,500 - $9,999" 9 "$10,000 - $14,999" 10 "$15,000 - $19,999" 11 "$20,000 or more"
lab values income income_vals2

lab define ownership_vals2 2 "Own" 1 "Rent"
lab values ownership ownership_vals2

lab define mortgage_vals2 2 "No" 1 "Yes"
lab values mortgage_payment mortgage_vals2

label define state_label  1 "Alabama" 2 "Alaska" 3 "Arizona" 4 "Arkansas" 5 "California" 6 "Colorado" 7 "Connecticut" 8 "Delaware" 9 "Florida" 10 "Georgia" 11 "Hawaii" 12 "Idaho" 13 "Illinois" 14 "Indiana" 15 "Iowa" 16 "Kansas" 17 "Kentucky" 18 "Louisiana" 19 "Maine" 20 "Maryland" 21 "Massachusetts" 22 "Michigan" 23 "Minnesota" 24 "Mississippi" 25 "Missouri" 26 "Montana" 27 "Nebraska" 28 "Nevada" 29 "New Hampshire" 30 "New Jersey" 31 "New Mexico" 32 "New York" 33 "North Carolina" 34 "North Dakota" 35 "Ohio" 36 "Oklahoma" 37 "Oregon" 38 "Pennsylvania" 39 "Rhode Island" 40 "South Carolina" 41 "South Dakota" 42 "Tennessee" 43 "Texas" 44 "Utah" 45 "Vermont" 46 "Virginia" 47 "Washington" 48 "West Virginia" 49 "Wisconsin" 50"Wyoming" 51 "Disctrict of Columbia"
label values state state_label  

decode state, gen(state_label)

gen region = .
replace region = 1 if inlist(state_label, "Connecticut","Maine","Massachusetts","New Hampshire","Rhode Island","Vermont")
replace region = 1 if inlist(state_label, "New England", "New Jersey","New York","Pennsylvania","Middle Atlantic")

replace region = 2 if inlist(state_label, "Illinois", "Indiana","Iowa","Kansas","Michigan","Minnesota","Missouri")
replace region = 2 if inlist(state_label, "Nebraska","North Dakota", "Ohio", "South Dakota","Wisconsin")

replace region = 3 if inlist(state_label, "North Carolina", "Oklahoma", "South Carolina", "Tennessee", "Texas", "Virginia", "West Virginia")
replace region = 3 if inlist(state_label, "Alabama", "Arkansas", "Delaware", "District of Columbia", "Florida", "Georgia")
replace region = 3 if inlist(state_label, "Georgia", "Kentucky", "Louisiana", "Maryland", "Mississippi")

replace region = 4 if inlist(state_label,  "New Mexico", "Oregon", "Utah", "Washington", "Wyoming", "Colorado")
replace region = 4 if inlist(state_label, "Alaska", "Arizona", "California", "Hawaii", "Idaho", "Montana", "Nevada")

lab define region_vals  1 "Northeast" 2 "Midwest" 3 "South" 4 "West"
lab values region region_vals

lab define Group_vals  0 "control" 1 "T1-script" 2 "T2-audio" 3 "T3-video"
lab values group Group_vals

gen age_30 = .
replace age_30 = 1 if age > 30
replace age_30 = 0 if age <= 30

gen employed_stat = .
replace employed_stat = 1 if inlist(employment,1,2)
replace employed_stat = 0 if employment == 3

gen nw = 0
replace nw = 1 if region == 1
gen mw = 0
replace mw = 1 if region == 2
gen south = 0
replace south = 1 if region == 3
gen west = 0
replace west  = 1 if region == 4

// --- --- --- --- --- --- --- --- 
// --- house price expectations 
// --- --- --- --- --- --- --- --- 
gen information_shock = 0.5 - pre_interest_change
replace information_shock = 0 if group == 0
gen information_shock_all = 0.5 - pre_interest_change

gen wording = 0
replace wording = 1 if inlist(group,1,2,3)
gen voice = 0
replace voice = 1 if inlist(group,2,3)
gen face = 0
replace face = 1 if inlist(group,3)

// evaluation
gen script_evaluation_full = script_evaluation
replace script_evaluation_full = 0 if inlist(group,0)
gen voice_evaluation_full = voice_evaluation
replace voice_evaluation_full = 0 if inlist(group,0,1)
gen face_evaluation_full = face_evaluation
replace face_evaluation_full = 0 if inlist(group,0,1,2)

replace face_evaluation = 0 if face_evaluation == .
replace voice_evaluation = 0 if voice_evaluation == .
replace script_evaluation = 0 if script_evaluation == .

//Aggregated evaluation
foreach var in script_evaluation_full voice_evaluation_full face_evaluation_full{
	
	gen `var'_aggre = .
	replace `var'_aggre = -1 if inlist(`var',-2,-1)
	replace `var'_aggre = 0 if inlist(`var',0)	
    replace `var'_aggre = 1 if inlist(`var',1,2)	
	
}

gen diff_house = post_house - pre_house
gen diff_house_f = post_house_f - pre_house

//Accuracy of attention question
foreach var in awhatwasthepolicyinterestratedec baccordingtothespeechtheuseconom  cregardingthepricelevelwhichofth {

	tab `var'	if group == 1
	tab `var'	if group == 2
    tab `var'	if group == 3
}

gen AC1 = .
replace AC1 = 1 if awhatwasthepolicyinterestratedec == 1
replace AC1 = 0 if inlist(awhatwasthepolicyinterestratedec,2,3,4,5,6)
gen AC2 = .
replace AC2 = 1 if baccordingtothespeechtheuseconom == 1
replace AC2 = 0 if inlist(baccordingtothespeechtheuseconom,2,3,4,5,6)
gen AC3 = .
replace AC3 = 1 if cregardingthepricelevelwhichofth == 1
replace AC3 = 0 if inlist(cregardingthepricelevelwhichofth,2,3,4,5,6)

save "$sDIR/analysis_data_non_verbal.dta", replace

// -----------------------------------------------------------------------------------------
// ------------------ Output dataset for Figure A.2 ----------------------------------------
//The code to produce figure A.2 is the matlab file: $sDIR/figures/FigureA2_plot.do
// -----------------------------------------------------------------------------------------
export delimited face_evaluation voice_evaluation script_evaluation group using "$sDIR/figures/data_figureA2.csv", nolabel replace

//*********************************************************************************
//***************************  Clean "raw_data_vignette_main"  ******************
//*********************************************************************************

clear
set more off
cd "$sDIR"
use "$sDIR/raw_data_vignette_main.dta", clear

//dealing state
encode state, generate(State)

// state - region
gen region = .
replace region = 1 if inlist(state, "Connecticut","Maine","Massachusetts","New Hampshire","Rhode Island","Vermont")
replace region = 1 if inlist(state, "New England", "New Jersey","New York","Pennsylvania","Middle Atlantic")

replace region = 2 if inlist(state, "Illinois", "Indiana","Iowa","Kansas","Michigan","Minnesota","Missouri")
replace region = 2 if inlist(state, "Nebraska","North Dakota", "Ohio", "South Dakota","Wisconsin")

replace region = 3 if inlist(state, "North Carolina", "Oklahoma", "South Carolina", "Tennessee", "Texas", "Virginia", "West Virginia")
replace region = 3 if inlist(state, "Alabama", "Arkansas", "Delaware", "District of Columbia", "Florida", "Georgia")
replace region = 3 if inlist(state, "Georgia", "Kentucky", "Louisiana", "Maryland", "Mississippi")

replace region = 4 if inlist(state,  "New Mexico", "Oregon", "Utah", "Washington", "Wyoming")
replace region = 4 if inlist(state, "Alaska", "Arizona", "California", "Hawaii", "Idaho", "Montana", "Nevada")

lab define region_vals  1 "Northeast" 2 "Midwest" 3 "South" 4 "West"
lab values region region_vals
drop state

// no vs some vs a lot experience
gen ex1_3 = ex1
replace ex1_3  = 0 if ex1_3  == 1
replace ex1_3  = 1 if inlist(ex1_3,2,3)
replace ex1_3  = 2 if inlist(ex1_3,4,5)
lab define ex1_3_vals 0 "No experience at all" 1 "Have a few/some experience" 2 "Have many/a lot of experience"
lab values ex1_3 ex1_3_vals

//dealing gender
encode gender, generate(Gender)
drop if Gender == .
drop gender
//dealing education
gen Education = .

replace Education = 1 if education == "Less than high school"
replace Education = 2 if education == "High school diploma (or equivalent)"
replace Education = 3 if education == "Some college but no degree (including academic, vocational or occupational programs)"
replace Education = 4 if education == "Associate/Junior College degree (including academic, vocational, or occupational programs)"
replace Education = 5 if education == "Bachelor's Degree (For example: BA, BS)"
replace Education = 6 if education == "Master's Degree (For example: MA, MBA, MS, MSW)"
replace Education = 7 if education == "Professional Degree (For example: MD, JD, DDS)"
replace Education = 8 if education == "Doctoral Degree (For example: PhD)"

labmask Education, values(education)
drop education

gen colleage = 0
replace colleage = 1 if Education >= 5
//dealing employment type
gen Employment = .

replace Employment = 0 if employment == "Unemployment"
replace Employment = 1 if employment == "Self-employed"
replace Employment = 2 if employment == "Employed"

labmask Employment, values(employment)
drop employment

order age, last

gen 	age_cat = 1 if age >=16 & age < 30
replace age_cat = 2 if age >=30 & age < 50
replace age_cat = 3 if age >=50 & age < 70
replace age_cat = 4 if age >=70 & age < .
lab define age_vals 1 "16 to 29" 2 "30 to 49" 3 "over 50" 4 "over 70"
lab values age_cat age_vals

//dealing marriage
gen Marriage = .

replace Marriage = 0 if marriage == "Single/Divorced"
replace Marriage = 1 if marriage == "Married"
labmask Marriage, values(marriage)
drop marriage

//dealing children
gen Children = . 
replace Children = 0 if children == "No"
replace Children = 1 if children == "Yes"
labmask Children, values(children)
drop children
order totalhh, last

//dealing income and average/middle-point income in each category
gen Income = .
gen Income_mid = .

replace Income = 1 if income == "Less than $1,000"
replace Income = 2 if income == "$1,000 - $1,999"
replace Income = 3 if income == "$2,000 - $2,999"
replace Income = 4 if income == "$3,000 - $3,999"
replace Income = 5 if income == "$4,000 - $4,999"
replace Income = 6 if income == "$5,000 - $5,999"
replace Income = 7 if income == "$6,000 - $7,499"
replace Income = 8 if income == "$7,500 - $9,999"
replace Income = 9 if income == "$10,000 - $14,999"
replace Income = 10 if income == "$15,000 - $19,999"
replace Income = 11 if income == "$20,000 or more"

replace Income_mid = 500 if income == "Less than $1,000"
replace Income_mid = 1500 if income == "$1,000 - $1,999"
replace Income_mid = 2500 if income == "$2,000 - $2,999"
replace Income_mid = 3500 if income == "$3,000 - $3,999"
replace Income_mid = 4500 if income == "$4,000 - $4,999"
replace Income_mid = 5500 if income == "$5,000 - $5,999"
replace Income_mid = 6250 if income == "$6,000 - $7,499"
replace Income_mid = 8750 if income == "$7,500 - $9,999"
replace Income_mid = 12500 if income == "$10,000 - $14,999"
replace Income_mid = 17500 if income == "$15,000 - $19,999"
replace Income_mid = 50000 if income == "$20,000 or more"

labmask Income, values(income)
labmask Income_mid, values(income)
drop income

xtile earn_q = Income, n(3)

// generate weights
gen wt = .
replace wt = 0.640244 if Marriage == 0 & Gender == 2 & Income == 1
replace wt = 0.346322 if Marriage == 0 & Gender ==  2 & Income == 2
replace wt = 0.380815 if Marriage == 0 & Gender == 2 & Income ==  3
replace wt = 0.395548 if Marriage == 0 & Gender == 2 & Income ==  4
replace wt = 0.22215  if Marriage == 0 & Gender == 2 & Income ==  5

replace wt = 0.274085 if Marriage == 0 & Gender == 2 & Income ==  6
replace wt = 0.538626 if Marriage == 0 & Gender ==  2 & Income == 7
replace wt = 1.260873 if Marriage == 0 & Gender == 2 & Income == 8 
replace wt = 1.89051  if Marriage == 0 & Gender == 2 & Income == 9
replace wt = 0.676787 if Marriage == 0 & Gender == 2 & Income == 10

replace wt = 0.932856 if Marriage == 0 & Gender == 2 & Income ==  11
replace wt = 1.493903 if Marriage == 0 & Gender == 1 & Income ==  1
replace wt = 0.791593 if Marriage == 0 & Gender == 1 & Income ==  2
replace wt = 0.465441 if Marriage == 0 & Gender == 1 & Income ==  3
replace wt = 0.508561 if Marriage == 0 & Gender == 1 & Income ==  4

replace wt = 0.22698  if Marriage == 0 & Gender == 1 & Income == 5 
replace wt = 0.332818 if Marriage == 0 & Gender ==  1 & Income ==  6
replace wt = 1.020555 if Marriage == 0 & Gender ==  1 & Income ==  7
replace wt = 1.40097  if Marriage == 0 & Gender ==  1 & Income ==  8
replace wt = 3.213867 if Marriage == 0 & Gender ==  1 & Income ==  9

replace wt = 1.353574 if Marriage == 0 & Gender ==  1 & Income ==  10
replace wt = 1.112251 if Marriage == 0 & Gender ==  1 & Income ==  11
replace wt = 2.023391 if Marriage == 1 & Gender ==  2 & Income ==  1
replace wt = 1.128675 if Marriage == 1 & Gender ==  2 & Income ==  2
replace wt = 0.684327 if Marriage == 1 & Gender ==  2 & Income ==  3

replace wt = 0.819511 if Marriage == 1 & Gender ==  2 & Income ==  4
replace wt = 0.491256 if Marriage == 1 & Gender ==  2 & Income ==  5
replace wt = 1.07338  if Marriage == 1 & Gender ==  2 & Income ==  6
replace wt = 3.369298 if Marriage == 1 & Gender ==  2 & Income ==  7
replace wt = 3.927595 if Marriage == 1 & Gender ==  2 & Income ==  8

replace wt = 2.069094 if Marriage == 1 & Gender ==  2 & Income ==  9
replace wt = 0.99671  if Marriage == 1 & Gender ==  2 & Income ==  10
replace wt = 3.81259  if Marriage == 1 & Gender ==  2 & Income ==  11
replace wt = 4.561865 if Marriage == 1 & Gender == 1  & Income ==  1
replace wt = 1.90937  if Marriage == 1 & Gender == 1 & Income ==  2

replace wt = 2.049761 if Marriage == 1 & Gender == 1  & Income ==  3
replace wt = 2.388029 if Marriage == 1 & Gender == 1 & Income ==  4
replace wt = 2.010845 if Marriage == 1 & Gender == 1 & Income ==  5
replace wt = 3.493712 if Marriage == 1 & Gender == 1 & Income ==  6
replace wt = 6.52392  if Marriage == 1 & Gender == 1 & Income ==  7

replace wt = 2.923915 if Marriage == 1 & Gender == 1 & Income ==  8
replace wt = 4.51656  if Marriage == 1 & Gender == 1 & Income ==  9
replace wt = 1.85402  if Marriage == 1 & Gender ==  1 & Income ==  10
replace wt = 0.746661 if Marriage == 1 & Gender == 1 & Income ==  11


//dealing house ownership
gen Ownership = . 
replace Ownership = 0 if ownership == "Renting"
replace Ownership = 1 if ownership == "Owning"
labmask Ownership, values(ownership)
drop ownership

//dealing mortgage payment
gen Mortgage_payment = . 
replace Mortgage_payment = 0 if mortgage  == "No"
replace Mortgage_payment = 1 if mortgage == "Yes"
labmask Mortgage_payment , values(mortgage)
drop mortgage

gen revision = house_2 - house_1
gen rev_direction = .
replace rev_direction = 1 if revision > 0
replace rev_direction = 0 if revision == 0
replace rev_direction = -1 if revision < 0

replace rev_direction = 0 if abs(revision) < 1

tab rev_direction

//dealing with MCQ answers
replace mec1 = 0 if mec1 == .
replace mec2 = 0 if mec2 == .
replace mec3 = 0 if mec3 == .
replace mec4 = 0 if mec4 == .
replace mec5 = 0 if mec5 == .
replace mec6 = 0 if mec6 == .
replace mec7 = 0 if mec7 == .
replace mec8 = 0 if mec8 == .
replace mec9 = 0 if mec9 == .

gen P_neg = mec1 + mec2 + mec5 + mec7 + mec8 + mec9
gen P_neg2 = P_neg
sum P_neg
//standardization
replace P_neg = P_neg/1.346247

gen P_pos = mec3+ mec4+ mec6
gen P_pos2 = P_pos
sum P_pos
//standardization
replace P_pos = P_pos/0.9062623

//dealing with open-ended answers
foreach var in 1 2 3 4 5 6 7 8 9 {
	
		replace mec`var'_open = 0 if mec`var'_open == .
	}

replace	nonsense_open = 0 if nonsense_open == .
gen P_neg_open = mec1_open + mec2_open + mec5_open + mec7_open + mec8_open + mec9_open
gen P_neg2_open = P_neg_open
sum P_neg_open
//standardization
replace P_neg_open = P_neg_open/0.8031919

gen P_pos_open = mec3_open+ mec4_open+ mec6_open
gen P_pos2_open = P_pos_open
sum P_pos_open
//standardization
replace P_pos_open = P_pos_open/0.5634843

save "$sDIR/analysis_data_vignette_main.dta", replace
// -----------------------------------------------------------------------------------------
// ------------------ Output dataset for Figure A.4 ----------------------------------------
//The code to produce figure A.4 is the matlab file: $sDIR/figures/FigureA4_plot.do
// -----------------------------------------------------------------------------------------
export delimited revision house_2 house_1 using "$sDIR/figures/data_figureA4.csv", nolabel replace

// //*********************************************************************************
// //***************************  Clean "raw_vignette_internal_validation"  ******************
// //*********************************************************************************
// clear
// set more off
// cd "$sDIR"
// use "$sDIR/raw_vignette_internal_validation", clear
// replace mec = 0 if mec == .
// replace mec_open = 0 if mec_open == .
//
// save "$sDIR/analysis_vignette_internal_validation.dta", replace

//*********************************************************************************
//***************************  Clean "raw_vignette_pooled"  ******************
//*********************************************************************************
clear
set more off
cd "$sDIR"
use "$sDIR/raw_vignette_pooled", clear

lab define SD_vals 1 "demand channel" 2 "supply channel" 3 "Inflation channel"
lab values sd SD_vals
gen ex1_3 = ex1

replace ex1_3  = 0 if ex1_3  == 1
replace ex1_3  = 1 if inlist(ex1_3,2,3)
replace ex1_3  = 2 if inlist(ex1_3,4,5)
lab define ex1_3_vals 0 "No experience at all" 1 "Have a few/some experience" 2 "Have many/a lot of experience"
lab values ex1_3 ex1_3_vals

save "$sDIR/analysis_vignette_pooled.dta", replace
//*********************************************************************************
//***************************  Clean "raw_data_robust_wave"  ******************
//*********************************************************************************
clear
set more off
cd "$sDIR"
use "$sDIR/raw_data_robust_wave.dta", clear

lab define news_heard_vals2 1 "never" 2 "seldom" 3 "sometimes" 4 "often"
lab values news_heard  news_heard_vals2

lab define fed_important_vals2 1 "very unimportant" 2 "somewhat unimportant" 3 "somewhat important" 4 "important"
lab values fed_important  fed_important_vals2

lab define pre_knowledge_vals2 -1 "Home prices will decrease" 0 "Home prices will stay the same" 1 "Home prices will increase" 99 "don't know"
lab values pre_knowledge  pre_knowledge_vals2

lab define hp_better_vals2 -1 "Worse off" 0 "No change" 1 "better off"
lab values hp_better  hp_better_vals2

lab define house_tenure_vals2 1 "I own a home and live in it" 2 "I own a home but currently rent another residence" 3 "I rent my current residence and do not own a house" 4 "I live with family or friends without paying rent" 5 "I live in student or employer-provided housing" 6 "Other"
lab values house_tenure  house_tenure_vals2

lab define mortgage_vals2 1 "Yes, owner" 0 "No, owner" 99 "No, renter"
lab values mortgage  mortgage_vals2

lab define pre_hp_direction_vals2 1 "increase" -1 "decrease" 0 "stay the same"
lab values pre_hp_direction  pre_hp_direction_vals2

lab define pre_hp_confi_vals2 2 "Very confident" 1 "Confident" 0 "Neutral" -1 "Not confident" -2 "Not confident at all"
lab values pre_hp_confi  pre_hp_confi_vals2

lab define perc_ffr_direction_vals2 1 "increase" -1 "decrease" 
lab values perc_ffr_direction  perc_ffr_direction_vals2

lab define pre_ffr_confi_vals2 2 "Very confident" 1 "Confident" 0 "Neutral" -1 "Not confident" -2 "Not confident at all"
lab values pre_ffr_confi  pre_ffr_confi_vals2

lab define post_hp_direction_vals2 1 "increase" -1 "decrease" 0 "stay the same"
lab values post_hp_direction  post_hp_direction_vals2

gen script = .
gen voice = .
gen body = .

replace script  = script_1 if group == 6
replace voice = 3 if group == 6
replace body = 3 if group == 6

replace script  = script_2 if group == 7
replace voice  = voice_2 if group == 7
replace body = 3 if group == 7

replace script  = script_3 if group == 8
replace voice  = voice_3 if group == 8
replace body  = body_3 if group == 8

replace script  = script_4 if group == 9
replace body  = body_4 if group == 9
replace voice = 3 if group == 9

replace script = 0 if group == 1
replace voice = 0 if group == 1
replace body = 0 if group == 1

recode script (5 = 2) (4 = 1) (3 = 0) (2 = -1) (1 = -2)
lab define script_vals2 2 "very posivitive" 1 "positive" 0 "neutral" -1 "negative" -2 "very negative"
lab values script  script_vals2

recode voice (5 = 2) (4 = 1) (3 = 0) (2 = -1) (1 = -2)
lab define voice_vals2 2 "very posivitive" 1 "positive" 0 "neutral" -1 "negative" -2 "very negative"
lab values voice  voice_vals2

recode body (5 = 2) (4 = 1) (3 = 0) (2 = -1) (1 = -2)
lab define body_vals2 2 "very posivitive" 1 "positive" 0 "neutral" -1 "negative" -2 "very negative"
lab values body  body_vals2

lab define post_knowledge_vals2 -1 "Home prices will decrease" 0 "Home prices will stay the same" 1 "Home prices will increase" 99 "don't know"
lab values post_knowledge  post_knowledge_vals2

lab define gender_vals2 2 "Male" 1 "Female" 
lab values gender  gender_vals2

lab define employment_vals2 2 "Employed" 1 "Self-employed" 0 "Unemployed"
lab values employment  employment_vals2

lab define educ_vals2 2 "Less than high school" 4 "High school diploma (or equivalent)" 6 "Some college but no degree (including academic, vocational or occupational programs)" 8 "Associate/Junior College degree (including academic, vocational, or occupational programs)" 10 "Bachelor's Degree (For example: BA, BS)" 12 "Master's Degree (For example: MA, MBA, MS, MSW)" 14 "Doctoral Degree (For example: PhD)" 16 "Professional Degree (For example: MD, JD, DDS)"  
lab values educ  educ_vals2

lab define marriage_vals2 2 "Married" 1 "Single/divorced"
lab values marriage  marriage_vals2

lab define children_vals2 2 "Yes" 1 "No"
lab values children  children_vals2

lab define hh_size_vals2 1 "1" 2 "2" 3 "3" 4 "4" 5 "5" 6 "6" 7 "7" 8 "8 or more" 
lab values hh_size  hh_size_vals2

lab define head_vals2 2 "Yes" 1 "No"
lab values head  head_vals2

lab define income_vals2 1 "Less than $1,000" 2 "$1,000 - $1,999" 3 "$2,000 - $2,999" 4 "$3,000 - $3,999" 5 "$4,000 - $4,999" 6 "$5,000 - $5,999" 7 "$6,000 - $7,499" 8 "$7,500 - $9,999" 9 "$10,000 - $14,999" 10 "$15,000 - $19,999" 11 "$20,000 or more"
lab values income  income_vals2

lab define group_vals2 1 "control" 2 "current ffr" 3 "current ffr + future" 4 "current ffr + future + mechanism" 5 "current ffr + mechanism" 6 "script" 7 "audio" 8 "video" 9 "muted video"
lab values group group_vals2

gen wording = .
replace wording = 1 if inlist(group, 6,7,8,9)
replace wording = 0 if inlist(group, 1)

gen voicetone = .
replace voicetone = 1 if inlist(group, 7,8)
replace voicetone = 0 if inlist(group, 1,6,9)

gen faceexpress = .
replace faceexpress = 1 if inlist(group, 8,9)
replace faceexpress = 0 if inlist(group, 1,6,7)

gen pre_hp = pre_hp_direction * pre_hp_change
gen post_hp = post_hp_direction * post_hp_change

gen diff_hp = post_hp - pre_hp
gen diff_inf = post_inf - pre_inf

gen prior_link = .
replace prior_link = 1 if pre_knowledge == 1
replace prior_link = 0 if pre_knowledge != 1

gen post_link = .
replace post_link = 1 if post_knowledge == 1
replace post_link = 0 if post_knowledge != 1

gen diff_ffr = post_ffr - pre_ffr
gen perc_ffr = perc_ffr_direction*perc_ffr_change
gen shock_mp = 0.25 - perc_ffr

foreach var in script voice body{
	
	gen `var'_aggre = .
	replace `var'_aggre = -1 if inlist(`var',-2,-1)
	replace `var'_aggre = 0 if inlist(`var',0)
    replace `var'_aggre = 1 if inlist(`var',1,2)
	
}

save "$sDIR/analysis_data_robust_wave.dta", replace

//*********************************************************************************
//*************  Pool all datasets for analyzing knowledge change over time  ******
//*********************************************************************************

use "$sDIR/analysis_data_infor_provision.dta", clear
keep Gender Education Employed age Marriage Children Income State  Ownership know_channel2 Mortgage_payment
gen wave = 1
gen platform = 1
keep Gender Education Employed age Marriage Children Income State  Ownership know_channel2 Mortgage_payment wave platform
save "$sDIR/analysis_data_infor_provision_temp.dta", replace

use "$sDIR/analysis_data_vignette_main.dta", clear
gen Employed = .
replace Employed = 1 if inlist(Employment,1,2)
replace Employed = 0 if inlist(Employment,0)
gen know_channel2  = .
replace know_channel2 = 1 if house_2 - house_1 < 0
replace know_channel2 = 0 if house_2 - house_1 >= 0
gen wave = 1
gen platform = 1
keep Gender Education Employed age Marriage Children Income State  Ownership know_channel2 wave platform Mortgage_payment

save "$sDIR/analysis_data_vignette_main_temp.dta", replace

use "$sDIR/analysis_data_non_verbal.dta", clear
gen Gender = gender
gen Education = education
gen Employed = employed_stat
recode marriage (2=0)
gen Marriage = marriage
recode child (2=0)
gen Children = child
gen Income = income
gen State = state
recode ownership (2=1) (1=0)
gen Ownership= ownership
gen know_channel2= prior_knowledge_channel
gen wave = 2
gen platform = 2
recode mortgage_payment (2=0)
gen Mortgage_payment = mortgage_payment
keep Gender Education Employed age Marriage Children Income State  Ownership know_channel2 wave platform Mortgage_payment
save "$sDIR/analysis_data_non_verbal_temp.dta", replace

use "$sDIR/analysis_data_robust_wave.dta", clear
gen Gender = gender
gen Employed = .
replace Employed = 1 if inlist(employment,1,2)
replace Employed = 0 if inlist(employment,0)
gen Education = education
recode marriage (2=0)
gen Marriage = marriage
recode child (2=0)
gen Children = child
gen Income = income
gen State = state
gen Ownership = .
replace Ownership = 1 if inlist(house_tenure, 1,2)
replace Ownership = 0 if inlist(house_tenure, 3,4,5,6)
gen Mortgage_payment = .
replace Mortgage_payment = 1 if house_tenure == 2
replace Mortgage_payment = 0 if house_tenure != 2 & house_tenure != .

gen know_channel2 = pre_knowledge
gen wave = 3
gen platform = 2
recode know_channel2 (-1 = 0) (99 = 0)

replace Education = Education/2

keep Gender Education Employed age Marriage Children Income State Ownership know_channel2 wave platform Mortgage_payment
save "$sDIR/analysis_data_robust_wave_temp.dta", replace

use "$sDIR/analysis_data_infor_provision_temp.dta", clear
append using "$sDIR/analysis_data_vignette_main_temp.dta"
append using "$sDIR/analysis_data_non_verbal_temp.dta"
append using "$sDIR/analysis_data_robust_wave_temp.dta"

lab define wave_name 1 "Interest rate information experiment" 2 "Non-verbal experiment" 3 "Robustness wave"
lab values wave wave_name

save "$sDIR/analysis_data_pooled.dta", replace

erase analysis_data_infor_provision_temp.dta
erase analysis_data_vignette_main_temp.dta
erase analysis_data_non_verbal_temp.dta
erase analysis_data_robust_wave_temp.dta

